﻿/**
* @description  Slide that displays a text title centered in the show.
*/
package com.foed.applications.slideshow.slides {

	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	import com.foed.animation.TweenComposite;
	import com.foed.animation.Tweener;
	import com.foed.applications.slideshow.SlideShow;
	import com.foed.applications.slideshow.SlideProperties;

	public class TitleSlide extends Slide {
	
		static public var sProperties:SlideProperties;

		static protected const TEXT_ATTRIBUTE:String = "text";
		static protected const LINE_DELIMITER:String = "^";

		static private const TEXT_FONT:String = "Arial";
		static private const TEXT_SIZE:Number = 40;
		static private const TEXT_COLOR:uint = 0xFFFFFF;
		
//		[Embed(source="/arial.ttf", fontName="Arial", mimeType="application/x-font")]
//		public var ArialFont:Class;

		private var _scaler:TweenComposite;

		/**
		* @description  Constructor.
		*
		* @param  pSlideData  The XML defining a slide instance.
		* @param  pSlideShow  The main slide show application.
		*/
		public function TitleSlide(pSlideData:XML, pSlideShow:SlideShow) {
			super(pSlideData, pSlideShow);
		}
	
		/**
		* @description  Initializes slide and its properties, drawing its background and graphics when necessary.
		*
		* @param  pSlideData  The XML defining a slide instance.
		* @param  pSlideShow  The main slide show application.
		*/
		override protected function init(pSlideData:XML, pSlideShow:SlideShow):void {
			super.init(pSlideData, pSlideShow);
			var pField:TextField = new TextField();
			pField.width = _slideShow.properties.width;
			pField.height = 10;
			pField.multiline = true;
			pField.wordWrap = true;
			pField.autoSize = TextFieldAutoSize.LEFT;
			pField.embedFonts = true;
			pField.selectable = false;
			var pFormat:TextFormat = new TextFormat(TEXT_FONT, TEXT_SIZE, TEXT_COLOR);
			pFormat.align = TextFormatAlign.CENTER;
			pField.defaultTextFormat = pFormat;
			pField.text = getAttribute(TEXT_ATTRIBUTE).split(LINE_DELIMITER).join("\n");;
			pField.x = (_slideShow.properties.width-pField.width)/2;
			pField.y = (_slideShow.properties.height-pField.height)/2;
			_content.addChild(pField);
		}
	
		/**
		* @description  Triggers a slide to reveal itself, using its appropriate transition.
		*/
		override public function reveal():void {
			super.reveal();
			_scaler = new TweenComposite(
				[
				new Tweener(this, "scaleX", 1.5, 1, 400),
				new Tweener(this, "scaleY", 1.5, 1, 400)
				]
			);
			_scaler.start();
		}

	}

}